<?php

namespace App\Model;


/*
 *  用户调用次数统计
 * */

class DeviceCallCountsDaily extends Model
{


    //table name
    protected $table = 'device_call_counts_daily';

    /**
     * 可批量赋值的属性。
     *
     * @var array
     */
    protected $guarded = [];

    /*
     * 增加设备的使用次数
     */
    public static function addUseCount($mac)
    {
        //查询今天的数据是否有
        $date = date('Y-m-d');
        $todayCounts = self::where('mac',$mac)->where('call_date',$date)->first();
        if($todayCounts){
            self::where('mac',$mac)->where('call_date',$date)->increment('call_count');
        }else{
            $data = [
                'mac' => $mac,
                'call_date' => date('Y-m-d'),
                'call_count' => 1,
            ];
            self::create($data);
        }
    }
}
